package com.just.springboottrans.service;

import com.just.springboottrans.dao.PersonRepository;
import com.just.springboottrans.domain.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OtherServiceImpl implements OtherService{
    @Autowired
    PersonRepository personRepository;
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void methodC(Person person) {
        System.out.println("欢迎来到OtherService方法C");
        personRepository.saveAndFlush(person);
    }
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void methodD() {
        System.out.println("欢迎来到OtherService方法D");
        Person person=new Person();
        person.setName("大爷D");
        person.setAge(18);
        person.setAddress("兰州");
        personRepository.saveAndFlush(person);
    }

    @Transactional(propagation = Propagation.MANDATORY)
    @Override
    public void methodE(Person person) {
        personRepository.save(person);
    }
    @Transactional
    @Override
    public void methodF() {
        System.out.println("欢迎来到OtherService方法F");
        Person person=new Person();
        person.setName("大爷F");
        person.setAge(81);
        person.setAddress("呼伦贝尔");
        personRepository.saveAndFlush(person);
    }
}
